import type { Dialog, BrowserWindow } from 'electron'
import { exec } from 'node:child_process'

export async function getDirectory(dialog: Dialog, Window: BrowserWindow) {
  const { canceled, filePaths } = await dialog.showOpenDialog(Window, {
    properties: ['openDirectory'] // 只能选择一个，除非设置 'multiSelections'
  })

  // 点击取消
  return canceled ? '' : filePaths[0]
}

export const useExportText = (text: string, useExport: boolean) => {
  return useExport ? `export default ${text}` : text
}

export const useDev = (callback: () => any) => {
  process.env.NODE_ENV === 'development' && callback()
}

export const prettify = (path: string) => exec(`npx prettier --write ${path} --quote-props=consistent`)
